<template>
  <div id="app">
    <nav class="view-nav">
      <div class="nav-list">
        <!-- 全部 后端 前端 Android iOS 人工智能 开发工具 代码人生 阅读 -->
        <div class="nav-box" v-for="(item, index) in CourseList" :key="item.key" @click="CourseStyle(index)">
          <router-link :to="item.path" :class="index === styleIndex ? 'nav-item active' : 'nav-item'">{{ item.detail }}</router-link>
        </div>
        <router-view></router-view>
      </div>
    </nav>
  </div>
</template>

<script scoped>
export default {
  props: ['CourseList', 'NavId'],
  data() {
    return {
      styleIndex: 0,
    }
  },
  methods: {
    //点击变色
    CourseStyle(index) {
      this.styleIndex = index
      //切换一级路由时，二级路由选项样式默认置为0
      this.$refs.secondNav.styleIndex = 0
    },
  },
  name: 'Course',
}
</script>

<style scoped>
nav {
  display: block;
}
.view-nav,
.view-nav::before {
  left: 0;
  background-color: #fff;
}
.view-nav {
  position: fixed;
  top: 5rem;
  width: 100%;
  height: 3.833rem;
  z-index: 100;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  transition: all 0.2s;
  transform: translateZ(0);
  /* 页面放大后左对齐 */
  padding-left: 12px;
}
.nav-list {
  position: relative;
}
.view-nav .nav-list {
  max-width: 960px;
  height: 100%;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: left;
  line-height: 1;
}

.view-nav .nav-list .nav-item {
  font-size: 1.16rem;
  color: #71777c;
  position: relative;
  cursor: pointer;
  text-decoration: none;
  padding-left: 12px;
}
.view-nav .nav-list .nav-item.active {
  color: #1e80ff;
  padding-left: 12px;
}
.view-nav .nav-list .nav-item:hover {
  color: #1e80ff;
}
</style>